package com.edu.zut.cs.Business;


import com.edu.zut.cs.Dao.StudentDao;
import com.edu.zut.cs.Model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreSevere {
    StudentDao studentDao;
    @Autowired
    public void setStudentDao(StudentDao studentDao) {
        this.studentDao = studentDao;
    }

    //计算平均值
    public float avarageScore(){
        List<Student> studentList= studentDao.quireAll();
        float t=0;
        for(Student s : studentList){
            t+=s.getScore();
        }
        System.out.println(t/studentList.size());
        return t/studentList.size();

    }

    //添加业务
    public void insertStudent(Student student){
        studentDao.insertStudent(student);
    }

    //划分等级
    public void modifyclass(){
        List<Student> studentList= studentDao.quireAll();
        for(Student s : studentList){
            int score = (int)s.getScore();
            int scores = score/10;
            switch (scores){
                case 10:
                case 9:s.setScore(1f);break;
                case 8:s.setScore(2f);break;
                case 7:s.setScore(3f);break;
                case 6:s.setScore(4f);break;
                default:s.setScore(5f);
            }
            System.out.println(s.getScore());
            studentDao.modifyStudent(s);

        }
    }

}
